import ReactNative from 'react-native'

var ToastIOS = ReactNative.NativeModules.ToastIOS;

class Toast {
  SHORT = 2000;
  LONG = 3500;
  TOP = 1;
  CENTER = 2;
  BOTTOM = 3;
  

  show(message, duration, gravity) {
    this.showWithGravity(message, duration, gravity);
  }

  showWithGravity(message, duration, gravity) {
    if (typeof message != 'string') {
      message = JSON.stringify(message, null, 2);
    }
    if (duration != this.LONG) duration = this.SHORT;

    if (gravity != this.TOP && gravity != this.CENTER) {
      gravity = this.BOTTOM;
    }

    ToastIOS.makeText(message, duration, gravity);
  }
}

export default new Toast